import time

from common.parse_config import ParseConfig
from common.const import CASE_TYPE_CONCURRENCY
from common.utils import step as allure_step
from eval_lib.common.logger import get_logger
log = get_logger()


class BaseCase(object):

    CASE_TYPE = CASE_TYPE_CONCURRENCY

    @classmethod
    def setup_class(cls):
        cls.server_meta = ParseConfig.get_df_server_meta(case_type=cls.CASE_TYPE)
        log.info(
            f"start to run case {cls.class_name()}, df env: {cls.server_meta.to_json()}"
        )
        cls.start = time.time()
        with allure_step('The setup of the class'):
            pass
        cls._setup_class()

    @classmethod
    def teardown_class(cls):
        cls._teardown_class()
        log.info(
            f"case {cls.class_name()} spend time {time.time()-cls.start}s"
        )
        ParseConfig.release_df_env(cls.server_meta.server_ip)
        log.info(f"freed df env {cls.server_meta.to_json()}")
        with allure_step('The teardown of the class'):
            pass

    @classmethod
    def class_name(cls):
        return cls.__name__

    @classmethod
    def _setup_class(cls):
        pass

    @classmethod
    def _teardown_class(cls):
        pass
